home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Human Interface Toolbox / ItemHider / MultiHider.p < prev   
Encoding:
Text File  |  2000-09-28  |  4.1 KB  |  150 lines  |  [TEXT/CWIE]

  1. {
  2.     File:        MultiHider.p
  3.  
  4.     Contains:    
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1984-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/6/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22.  
  23. }
  24. PROGRAM MultiHider;
  25.  
  26. USES QuickDraw,Dialogs,Fonts,Windows;
  27.  
  28. CONST
  29.    itemOK =       7;
  30.    itemCancel =   8;
  31.    itemStat1 =    1;
  32.    itemStat2 =    3;
  33.    itemStat3 =    4;
  34.    itemEdit1 =    2;
  35.    itemEdit2 =    5;
  36.    itemEdit3 =    6;
  37.    itemHider =    9;
  38.    itemHideIt =   10;
  39.    itemMax =      10;
  40. VAR
  41.    ihDialog:   DialogPtr;
  42.    itemHit:    INTEGER;
  43.    theType:    INTEGER;
  44.    theHdl:     Handle;
  45.    theBox:     Rect;  
  46.    hidden:     BOOLEAN;
  47.  
  48.  
  49. PROCEDURE MyDrawItem(dlg: DialogPtr; theItem: INTEGER);
  50. VAR
  51.    iType:   INTEGER;
  52.    iBox:    Rect;
  53.    iHdl:    Handle; 
  54. BEGIN
  55.    GetDialogItem(dlg, theItem, iType, iHdl, iBox);
  56.    IF hidden THEN BEGIN
  57.       PenMode(notPatBic);
  58.       PenPat(qd.gray);
  59.       BackPat(qd.gray);
  60.       PaintRect(iBox);
  61.       FrameRect(iBox);
  62.       
  63.       PenMode(patCopy);
  64.       PenPat(qd.black);
  65.       BackPat(qd.white);
  66.       PenNormal;
  67.    END;
  68. END;
  69.  
  70.  
  71. PROCEDURE HideEditItem(theDialog: DialogPtr; theItem: INTEGER);
  72. VAR
  73.    iIndex:  INTEGER;
  74. BEGIN
  75.    (* Get the item information. *)
  76.    GetDialogItem(theDialog, theItem, theType, theHdl, theBox);
  77.    
  78.    (* Now check to see if it is the current text item.   *)
  79.    IF DialogPeek(theDialog)^.EditField + 1 = theItem THEN BEGIN
  80.       (* It is, so now we find the next editText item    *)
  81.       (* in the item list.  Start with the one we are on.*)
  82.       iIndex := theItem;
  83.       REPEAT
  84.          (* Increment to the next item, and make sure we *)
  85.          (* don't run off the end of the item list.      *)
  86.          iIndex := iIndex + 1;
  87.          IF iIndex > itemMax THEN iIndex := 1;
  88.          GetDialogItem(theDialog, iIndex, theType, theHdl, theBox);
  89.  
  90.          (* Keep going until we find an editText item.   *)
  91.          (* NOTE: THIS CODE ASSUMES THERE IS MORE THAN   *)
  92.          (*       ONE editText ITEM IN THE DIALOG.       *)
  93.       UNTIL (theType = editText);
  94.       SelectDialogItemText(theDialog, iIndex, 0, 0);
  95.    END;
  96.    GetDialogItem(theDialog, theItem, theType, theHdl, theBox);
  97.    SetDialogItem(theDialog, theItem, statText, theHdl, theBox);
  98.    DrawDialog(theDialog);
  99. END;
  100.  
  101.  
  102. PROCEDURE ShowEditItem(theDialog: DialogPtr; theItem: INTEGER);
  103. VAR
  104.    oldPort: GrafPtr;
  105. BEGIN
  106.    GetPort(oldPort);
  107.    SetPort(theDialog);
  108.    GetDialogItem(theDialog, theItem, theType, theHdl, theBox);
  109.    SetDialogItem(theDialog, theItem, editText, theHdl, theBox);
  110.    InvalRect(theBox);
  111.    DrawDialog(theDialog);
  112.    SetPort(oldPort);
  113. END;
  114.  
  115.  
  116. BEGIN {main program}
  117.    InitGraf (@qd.thePort);          {the big five inits}
  118.    InitFonts;
  119.    InitWindows;
  120.    TEInit;
  121.    InitDialogs (nil);
  122.  
  123.    hidden := FALSE;
  124.  
  125.    ihDialog := GetNewDialog(128, NIL, WindowPtr(-1));
  126.    GetDialogItem(ihDialog, itemHider, theType, theHdl, theBox);
  127.    SetDialogItem(ihDialog, itemHider, theType,Handle(NewUserItemProc(@MyDrawItem)), theBox);
  128.    ShowWindow(ihDialog);
  129.    
  130.    itemHit := 0;
  131.    WHILE ((itemHit <> itemOK) AND (itemHit <> itemCancel)) DO BEGIN
  132.       ModalDialog(nil, itemHit);
  133.       CASE itemHit OF
  134.          itemHideIt: BEGIN
  135.             GetDialogItem(ihDialog, itemHit, theType, theHdl, theBox);
  136.             hidden := NOT hidden;
  137.             IF hidden THEN BEGIN
  138.                SetControlValue(ControlHandle(theHdl), 1);
  139.                HideEditItem(ihDialog, itemEdit2);
  140.             END ELSE BEGIN
  141.                SetControlValue(ControlHandle(theHdl), 0);
  142.                ShowEditItem(ihDialog, itemEdit2);
  143.             END;
  144.          END;
  145.       END;
  146.    END;
  147.  
  148.    DisposeDialog(ihDialog);
  149. END.
  150.